// pages/meetingDetail/meetingDetail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    roomList: {},
    roomId: '',
    dayFlag: '0',
  },

  /* 显示地图 */
  gotoMap: function (e) {
    let LocationObj = e.currentTarget.dataset.location
    wx.openLocation({
      latitude: LocationObj.locateAtitude,
      longitude: LocationObj.locateLongitude,
      name: LocationObj.locateName,
      address: LocationObj.locateAddress
    })
  },

  /* 切换日期选项 */
  changeDayFlag: function (e) {
    this.setData({
      dayFlag: e.currentTarget.dataset.dayflag
    })
  },

  /* 点击会议室预约 */
  clickAppoint: function () {
    console.log("预约会议室！")
  },

  /* 编辑会议室内容 */
  edit: function () {
    wx.navigateTo({
      url: "/pages/admEditMeeting/admEditMeeting?id=" + this.data.roomId
    })
  },


  /* 删除会议室 */
  delete: function () {
    var that = this;
    wx.showLoading();
    //1.删除会议室的表单
    wx.cloud.database().collection('meetingRoom').doc(that.data.roomId).remove({
      success: function (res) {

        console.log("删除成功！")

        console.log(that.data.roomId)
        
        //2.删除会议室地图表单的数据
        wx.cloud.database().collection('meetingMapMsg').where({
          meetingId: that.data.roomId
        }).remove({})

        console.log("删除成功！")
        wx.hideLoading()
        wx.showToast({
          title: '成功删除会议室！',
          duration: 1000
        })
        setTimeout(function () {
          wx.navigateBack()
        }, 1000)

      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading({
      title: '载入数据中',
    })

    this.setData({
      roomId: options.id
    });
    wx.cloud.database().collection("meetingRoom").doc(options.id).get({
      success: res => {
        wx.hideLoading()
        let data = res.data;
        this.setData({
          roomList: data
        })
      }
    })
  },


})